package com.woniuxy.oa.dao.provider;

import com.woniuxy.oa.entity.Message;
import com.woniuxy.oa.entity.Notice;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author Mr X
 */
public class NoticeProvider {
    public String getSQL(Notice notice) {
        return new SQL() {
            {
                SELECT("*").FROM("oa_notice");
                if (notice != null) {
                    if (notice.getTitle() != null && notice.getTitle().trim().length() != 0) {
                        WHERE("title=#{title}");
                    }
                    if (notice.getPubDate() != null && notice.getPubDate().trim().length() != 0) {
                        WHERE("pubDate>#{pubDate}");
                    }
                    if (notice.getPubDate_max() != null && notice.getPubDate_max().trim().length() != 0) {
                        WHERE("pubDate<#{pubDate_max}");
                    }
                    if (notice.getStatus() != null && notice.getStatus().trim().length() != 0) {
                        WHERE("status=#{status}");
                    } else {
                        WHERE("status in ('1','2')");
                    }
                }
            }
        }.toString();
    }
}
